package com.lolc.ihm.component;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

import com.lolc.ihm.Constants;
import com.lolc.utils.Constant;


public class MyTeamBox  extends Box{

	private List<MyTeamPlayerBox> myTeamPlayerBoxes;
	
	private BannedChampionsBox bannedChampionBox; 
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MyTeamBox(int arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		this.myTeamPlayerBoxes=new ArrayList<MyTeamPlayerBox>();
	}
	
	public void initComponent()
	{
		this.setBounds(Constants.MY_TEAM_BOX_X, Constants.TEAM_BOX_Y, Constants.MY_TEAM_BOX_WIDTH, Constants.MY_TEAM_BOX_HEIGHT);
		
		//Title
		JLabel title = new JLabel(Constants.MY_TEAM_TITLE);
		title.setForeground(Color.WHITE);
		title.setAlignmentX(CENTER_ALIGNMENT);
		title.setFont(Constants.TEAM_TITLE_FONT);
		this.add(title);
						
		ButtonGroup btnGroup = new ButtonGroup();
		
		//Separator between  title and box
		Component separator = Box.createHorizontalGlue();
		separator.setPreferredSize(new Dimension(0,Constants.HORIZONTAL_SEPARATOR_HEIGHT));		
		this.add(separator);
		
		Box mainBox = Box.createVerticalBox();
		this.add(mainBox);
		
		mainBox.setBackground(Constants.COLOR_GRAY_1);
		mainBox.setOpaque(true);
		mainBox.setBorder(new LineBorder(Constants.COLOR_GRAY_2, 2));
		
		//Separator between  2 lists
		Component sep = Box.createHorizontalGlue();
		sep.setPreferredSize(new Dimension(0,Constants.HORIZONTAL_SEPARATOR_HEIGHT));		
		mainBox.add(sep);
		
		//Box players
		for (int i=0;i<Constant.NUMBER_PLAYER_PER_TEAM;i++)
		{
			MyTeamPlayerBox teamPlayer = new MyTeamPlayerBox(0,i);
			mainBox.add(teamPlayer);
			
			teamPlayer.initComponents(i);
			teamPlayer.validate();
			
			btnGroup.add(teamPlayer.getMyTurnRB());
			
			//Separator between  2 line
			Component separator2 = Box.createHorizontalGlue();
			separator2.setPreferredSize(new Dimension(0,Constants.VERTICAL_SEPARATOR_WIDTH));
			mainBox.add(separator2);	
			
			this.myTeamPlayerBoxes.add(teamPlayer);
		}
				
		//Separator between champions and banned champions
		Component separator3 = Box.createHorizontalGlue();
		separator3.setPreferredSize(new Dimension(0,3*Constants.VERTICAL_SEPARATOR_WIDTH));
		mainBox.add(separator3);
		
		//Banned champions
		Box horizontalBox = Box.createHorizontalBox();			
		mainBox.add(horizontalBox);
		
		//Space before
		Component spaceBefore = Box.createVerticalGlue();
		spaceBefore.setPreferredSize(new Dimension(Constants.ENNEMY_SPACE_BEFORE_AFTER_BANNED_CHAMPIONS_LIST, 0));
		horizontalBox.add(spaceBefore);
		
		this.bannedChampionBox = new BannedChampionsBox(BoxLayout.Y_AXIS);	
		horizontalBox.add(this.bannedChampionBox);
		this.bannedChampionBox.initComponents(Constants.MY_TEAM_BOX_X, Constants.TEAM_BOX_HEIGHT+100,Constants.MY_TEAM_BOX_WIDTH, Constants.BANNED_CHAMPIONS_HEIGHT,Constants.ENNEMY_SPACE_BEFORE_AFTER_BANNED_CHAMPIONS_LIST,Constants.GROUP_TEAM_BANNED_CHAMPIONS);
		this.bannedChampionBox.validate();
		
		//Space After
		Component spaceAfter= Box.createVerticalGlue();
		spaceAfter.setPreferredSize(new Dimension(Constants.ENNEMY_SPACE_BEFORE_AFTER_BANNED_CHAMPIONS_LIST, 0));
		horizontalBox.add(spaceAfter);
			
		mainBox.validate();
		this.validate();
	}

	public List<MyTeamPlayerBox> getMyTeamPlayerBoxes() {
		return myTeamPlayerBoxes;
	}

	public void setMyTeamPlayerBoxes(List<MyTeamPlayerBox> myTeamPlayerBoxes) {
		this.myTeamPlayerBoxes = myTeamPlayerBoxes;
	}

	/**
	 * @return the bannedChampionBox
	 */
	public BannedChampionsBox getBannedChampionBox() {
		return bannedChampionBox;
	}

	/**
	 * @param bannedChampionBox the bannedChampionBox to set
	 */
	public void setBannedChampionBox(BannedChampionsBox bannedChampionBox) {
		this.bannedChampionBox = bannedChampionBox;
	}
	
}
